package top.jianx.demo.shiro.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;
import top.jianx.demo.shiro.pojo.User;
import top.jianx.demo.shiro.service.UserService;

import javax.validation.Valid;
import java.util.List;

/**
 * @Description
 * @ClassName UserController
 * @Author Jianx  <[email]jianx@jianx.top>
 * @date 2020.03.04
 */
@RestController
@Api(value = "所有用户操作列表")
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "获取所有用户信息列表")
    @RequestMapping(value = "getAllUser", method = {RequestMethod.GET, RequestMethod.POST})
    public List<User> getAllUser(){
        return userService.findAllUser();
    }

    @ApiOperation(value = "获取id对应的用户信息列表")
    @RequestMapping(value = "getUserById/{id}", method = {RequestMethod.GET, RequestMethod.POST})
//    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer")
    public User getUserById(@PathVariable("id") Integer id){
        User userId = new User().setId(id);
        User user = userService.findUser(userId);
        return user;
    }
//    swagger2 接口文档生成demo is OK！
    @ApiOperation(value = "删除指定id的用户信息")
    @RequestMapping(value = "delete/{id}", method = {RequestMethod.POST})
    public String deleteUser(@PathVariable("id") Integer id){
        return userService.delete(id);
    }


    @ApiOperation(value = "更新指定id的用户信息")
    @RequestMapping(value = "update/{id}", method = {RequestMethod.POST})
    public String updateUser(@Valid User user){
        return userService.update(user);
    }
}
